package cn.south.campus.admin.sys.model.vo;

import cn.south.campus.admin.sys.model.entity.SysMenu;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * @author chow
 * @since 2024/10/31
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysMenuVo extends BaseVO {
    /**
     * 名称
     */
    private String menuName;
    /**
     * 图标
     */
    private String icon;
    /**
     * 父级ID
     */
    private Long parentId;
    /**
     * 路由
     */
    private String path;
    /**
     * 权限code
     */
    private String permissionCode;

    private Integer sort;
    /**
     * 子菜单
     */
    private List<SysMenuVo> children;

    public static SysMenuVo convert(SysMenu sysMenu) {
        SysMenuVo sysMenuVo = new SysMenuVo();
        sysMenuVo.setId(sysMenu.getId());
        sysMenuVo.setMenuName(sysMenu.getMenuName());
        sysMenuVo.setIcon(sysMenu.getIcon());
        sysMenuVo.setParentId(sysMenu.getParentId());
        sysMenuVo.setPermissionCode(sysMenu.getPermissionCode());
        sysMenuVo.setPath(sysMenu.getPath());
        sysMenuVo.setSort(sysMenu.getSort());
        sysMenuVo.setCreateTime(DateUtil.format(sysMenu.getCreateTime()));
        sysMenuVo.setUpdateTime(DateUtil.format(sysMenu.getUpdateTime()));
        return sysMenuVo;
    }
    public static SysMenu convert(SysMenuVo vo) {
        SysMenu sysMenu = new SysMenu();
        sysMenu.setId(vo.getId());
        sysMenu.setMenuName(vo.getMenuName());
        sysMenu.setIcon(vo.getIcon());
        sysMenu.setParentId(vo.getParentId());
        sysMenu.setPath(vo.getPath());
        sysMenu.setSort(vo.getSort());
        sysMenu.setPermissionCode(vo.getPermissionCode());
        sysMenu.setCreateTime(DateUtil.parseString(vo.getCreateTime()));
        sysMenu.setUpdateTime(DateUtil.parseString(vo.getUpdateTime()));
        return sysMenu;
    }
}
